package com.sinodoggo.shitcloud.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sinodoggo.shitcloud.entity.Comment;
import com.sinodoggo.shitcloud.mapper.CommentMapper;
import com.sinodoggo.shitcloud.service.ICommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author sinodoggo
 * @since 2022-11-26
 */
@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements ICommentService {
    @Resource
    private CommentMapper mapper;

    @Override
    public List<Comment> getCorrespondingComments(Integer articleId) {
        return mapper.getCorrespondingComments(articleId);
    }

    /**
     * 根据博文ID删除相应评论
     * @param id 博文ID
     */
    @Override
    public void removeCommentsByArticleId(Integer id) {
        QueryWrapper<Comment> wrapper = new QueryWrapper<>();
        wrapper.eq("article_id", id);
        mapper.delete(wrapper);
    }
}
